layui.define(['jquery','form', 'element', 'YsModal'], function (exports) {
	"use strict";
	var $ = layui.jquery,form=layui.form,object = {
		c: {data:[]}, // 配置项
		f: function (c) { // 数据初始化
			var s=new Date().getTime(),t = this;
			t.c.id = c.id?c.id:'simple_table_TP_BoutiqueSiteDetail';
			t.c.id_tab_1 = 'id_tab_1_'+s;
			t.c.id_tab_2 = 'id_tab_2_' + s;
			t.c.id_tab_3 = 'id_tab_3_' + s;
			t.c.id_grid_1 = 'id_grid_1_' + s;
			t.c.id_grid_2 = 'id_grid_2_' + s;
			t.c.id_grid_3 = 'id_grid_3_' + s;
			t.c.data = c.data; // 数据
			t.c.data2 = c.data2; // 调货信息数组
			t.c.data3 = c.data3; // 权限信息数据
			
			/**自定义的字段，是否流转中**/
			t.c.onProcess = c.onProcess;
			t.c.boutiqueId = c.boutiqueId;
			t.c.code = c.code;

			//复选框选中，存放行号，表1
			t.c.checkedIndex_1 = [];
			t.c.checkedIndex_3 = [];
		},
		load:function () { // 加载控件
			var h = ``
				+ `<div class="layui-tab layui-tab-brief" style="background-color: #fff; height:877px;" >`
					+ `<ul class="layui-tab-title">`
						+ `<li class="layui-this">1、站点信息</li>`
						+ `<li>2、调货信息</li>`
						+ `<li>3、权限信息</li>`
					+ `</ul>`

					+ `<div class="layui-tab-content">`
						+ `<div class="layui-tab-item layui-show">`
							+ `<div class="layui-table-tool" style="padding: 0; min-height: 0; background-color: #ffffff;" id="` + this.c.id_tab_1 + `">`
								+ `<div class="layui-table-tool-temp">`;
								if (this.c.onProcess == 0) {
									h+=`<div class="layui-btn-container" style="padding-bottom: 10px;padding-left: 10px;">`
										+ `<a class="layui-btn layui-btn-normal layui-btn-sm " lay-event="event-to-select"><i class="iconfont icon-add-btn"></i>新增</a>`
										+ `<a class="layui-btn layui-btn-danger layui-btn-sm " lay-event="event-to-del" ><i class="layui-icon layui-icon-delete"></i>删除</a>`
									+ `</div>`;
								}
								h+= `<div class="layui-form layui-form-item" pane>`
										+ `<div id="` + this.c.id_grid_1 + `">`
											+ this.loadTable()
										+ `</div>`
									+ `</div>`
								+ `</div>`
							+ `</div>`
						+ `</div>`
						+ `<div class="layui-tab-item">`
							+ `<div class="layui-table-tool" style="padding: 0; min-height: 0; background-color: #ffffff;" id="` + this.c.id_tab_2 + `">`
								+ `<div class="layui-table-tool-temp" style="padding-right: 0;">`;
								if (this.c.onProcess == 0) {
									h+= `<div class="layui-btn-container" style="padding-bottom: 10px;padding-left: 10px;">`
										+ `<a class="layui-btn layui-btn-normal layui-btn-sm btn-add-sys_col_all"><i class="layui-icon layui-icon-addition"></i>添加商品</a>`
										+ `<a class="layui-btn layui-btn-normal layui-btn-sm btn-save-tp_boutique_setting"><i class="layui-icon layui-icon-edit"></i>保存调货信息</a>`
									+ `</div>`;
								}
									h+= `<div class="layui-form layui-form-item" pane>`
										+ `<div id="` + this.c.id_grid_2 + `">`
											+ this.loadGrid_2()
										+ `</div>`
									+ `</div>`
								+ `</div>`
							+ `</div>`
						+ `</div>`
						+ `<div class="layui-tab-item">`
							+ `<div class="layui-table-tool" style="padding: 0; min-height: 0; background-color: #ffffff;" id="` + this.c.id_tab_3 + `">`
								+ `<div class="layui-table-tool-temp">`;
									if (this.c.onProcess == 0) {
										h+=`<div class="layui-btn-container" style="padding-bottom: 10px;padding-left: 10px;">`
											+ `<a class="layui-btn layui-btn-normal layui-btn-sm " lay-event="event-to-select-3"><i class="iconfont icon-add-btn"></i>新增</a>`
											+ `<a class="layui-btn layui-btn-danger layui-btn-sm " lay-event="event-to-del-3" ><i class="layui-icon layui-icon-delete"></i>删除</a>`
											+ `</div>`;
									}
									h+= `<div class="layui-form layui-form-item" pane>`
										+ `<div id="` + this.c.id_grid_3 + `">`
											+ this.loadGrid_3()
										+ `</div>`
									+ `</div>`
								+ `</div>`
							+ `</div>`
						+ `</div>`
					+ `</div>`
				+ `</div>`;
			$('#'+this.c.id).html(h);
			this.listenAll();
		},
		loadTable:function () { // 加载表格
			return ``
			+ `<div class="layui-table-box">`
				+ `<div class="layui-table-header" style="height: 300px; max-height: 300px; overflow: auto; background-color: #ffffff;">`
					+ `<table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-skin="grid" lay-even="" style="margin: 0;">`
						+ `<thead>`
							+ this.loadTableOfThead()
						+ `</thead>`
						+ `<tbody>` + this.loadTableOfTbody()+`</tbody>`
					+ `</table>`
				+ `</div>`
			+ `</div>`;
		},
		loadTableOfThead:function () { // 加载表头
			var h = `<thead>`;
			h +=`<tr>`;
			h += `<th style="width:1.9%; text-align: center; color: #000000;padding: 0 !important;">
							<input type="checkbox" id="checkAll" lay-skin="primary" lay-filter="checkAll">
						</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">平台编码</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">平台名称</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">站点</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">区域</th>`;

			h += `<th style="width:4%; text-align: center; color: #000000;">操作</th>`;
			h += `</tr>`;
			h + `</thead>`;
			return h;
		},
		loadTableOfTbody:function () { // 加载表tbody
			var t = this;
			var h = `<tbody id="tbody">`;
			for(var i=0;i<t.c.data.length;i++){
				h += `<tr id="table_th_`+i+`">`;
				h += t.loadTableTdOfTbody(t.c.data[i],i);
				h+= `</tr>`;
			}
			
			h += `</tbody>`;
			return h;
		},
		loadTableTdOfTbody:function (data,i) { // 加载表格行
			var h = ``;
			h += `<td style="text-align:center;padding:0;">
					<input type="checkbox" class="chBox"  lay-skin="primary" data-index="` + i + `"  lay-filter="checkBoxOne">
					</td>`;
			h += `<td style="text-align:center; padding: 0;">` + data.platformCode + `</td>`;
			h += `<td style="text-align:center; padding: 0;">` + data.platformName + `</td>`;
			h += `<td style="text-align:center; padding: 0;">` + data.countryName + `</td>`;
			h += `<td style="text-align:center; padding: 0;">` + data.regionName + `</td>`;
			if(this.c.onProcess == 0) {
				h += `<td style="text-align:center; padding: 0;"><button type="button" class="layui-btn layui-btn-xs" data-index="` + i + `" lay-filter="editSingle"><i class="layui-icon layui-icon-edit"></i>编辑详情</button>`;
			}else {
				h += `<td style="text-align:center; padding: 0;"><button type="button" class="layui-btn layui-btn-xs" data-index="` + i + `" lay-filter="detailSingle"><i class="layui-icon layui-icon-edit"></i>查看详情</button>`;
			}
			return h;
		},
		loadGrid_2:function () { // 加载表格
			return `<table class="layui-table" lay-skin="row" style="margin:0;"><thead>`+this.loadGrid_2_OfThead()+`</thead><tbody>`+this.loadGrid_2_OfTbody()+`</tbody></table>`;
		},
		reloadGrid_2:function () { // 重新加载第二张表格
			$('#'+this.c.id_grid_2).html(this.loadGrid_2());
			this.listenGrid_2();
		},
		loadGrid_2_OfThead:function () { // 加载表头
			var h = `<thead><tr>`;
			h += `<th style="width:60px; text-align: center; color: #000000;padding: 0 !important;">
							<input type="checkbox" id="checkAll_2" lay-skin="primary" lay-filter="checkAll_2">
						</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">商品编码</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">属性</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">仓库</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">箱规尺寸(cm)</th>`;
			h += `<th style="width:6%; text-align: center;color: #000000;padding: 0 !important;">箱规重量(kg)</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">建议售价(当地币)</th>`;
			h += `<th style="width:4%; text-align: center;color: #000000;padding: 0 !important;">单价</th>`;
			h += `<th style="width:4%; text-align: center;color: #000000;padding: 0 !important;">单位</th>`;
			h += `<th style="width:4%; text-align: center;color: #000000;padding: 0 !important;">单箱数量</th>`;
			h += `<th style="width:5%; text-align: center;color: #000000;padding: 0 !important;">首次起订箱数</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">再次起订箱数</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">生产货期(天)</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">预计到货时间</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">发货数量</th>`;
			h += `<th style="width:8%; text-align: center;color: #000000;padding: 0 !important;">预购数量</th>`;
			if (this.c.onProcess == 0) {
				h += `<th style="width:15%; text-align: center;color: #000000;">操作</th></tr></thead>`;
			}
			return h;
		},
		loadGrid_2_OfTbody:function () { // 加载表tbody
			var t = this;
			var h = `<tbody id="tbody_2">`;
			for(var i=0;i<t.c.data2.length;i++){
				h += `<tr id="table_2_th_`+i+`">`;
				h += t.loadTableTdOfTbody_2(t.c.data2[i],i);
				h+= `</tr>`;
			}
			
			h += `</tbody>`;
			return h;
		},
		loadTableTdOfTbody_2:function (data,i) { // 加载表格行
			var h = ``;
			h += `<td style="text-align:center;padding:0;">
					<input type="checkbox" class="chBox_2"  lay-skin="primary" data-index="` + i + `"  lay-filter="checkBoxOne_2">
					</td>`;
			if (this.c.onProcess == 0) {
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;" data-type="code">` + data.code + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="text"  class="text_align_center layui-input" data-index="` + i + `" data-type="attr" lay-filter="_input"  value="` + (data.attr ? data.attr : ``) + `" ></td>`;
				h += `<td style="text-align:center;	width:8%;padding: 0 !important;border-width: 1px;"><input type="text"  class="text_align_center layui-input" data-index="` + i + `" data-type="warehouse" lay-filter="_select_warehose"  value="` + (data.warehouse ? data.warehouse : ``) + `" readonly></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.size ? data.size : ``) + `<i class="layui-icon layui-icon-more" style="position:absolute;top: 10px !important;right: 5px !important; width: 20px;" data-index="` + i + `" lay-filter="_select_gaugemaintenance"></i></td>`;
				h += `<td style="text-align:center; width:6%;padding: 0 !important;border-width: 1px;">` + (data.weight ? data.weight : ``) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="retailPrice" lay-filter="_input"  value="` + (data.retailPrice ? data.retailPrice : ``) + `" ></td>`;
				h += `<td style="text-align:center; width:4%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="originPrice" lay-filter="_input"  value="` + (data.originPrice ? data.originPrice : ``) + `" ></td>`;
				h += `<td style="text-align:center;	width:4%;padding: 0 !important;border-width: 1px;"><input type="text"  class="text_align_center layui-input" data-index="` + i + `" data-type="unitName" lay-filter="_input"  value="` + (data.unitName ? data.unitName : ``) + `"></td>`;
				h += `<td style="text-align:center; width:4%;padding: 0 !important;border-width: 1px;">` + (data.numPerBox ? data.numPerBox : ``) + `</td>`;
				h += `<td style="text-align:center; width:5%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="numBuyMin" lay-filter="_input"  value="` + (data.numBuyMin ? data.numBuyMin : ``) + `"></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="numBuyMinSecond" lay-filter="_input"  value="` + (data.numBuyMinSecond ? data.numBuyMinSecond : ``) + `"></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="period" lay-filter="_input"  value="` + (data.period) + `"></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="text"  class="text_align_center layui-input" data-index="` + i + `" data-type="timeArrivePredict" lay-filter="_select_timeArrivePredict"  value="` + (data.timeArrivePredict ? data.timeArrivePredict : ``) + `" readonly></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="numAll" lay-filter="_input"  value="` + (data.numAll) + `"></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><input type="number"  class="text_align_center layui-input" data-index="` + i + `" data-type="numPreBuy" lay-filter="_input"  value="` + (data.numPreBuy) + `"></td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;"><a class="layui-btn layui-btn-danger layui-btn-sm" data-index="` + i + `" lay-event="event-to-delete-single-2"><i class="layui-icon layui-icon-delete"></i>删除</a></td>`;
			}else {
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;" data-type="code">` + data.code + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.attr ? data.attr : ``) + `</td>`;
				h += `<td style="text-align:center;	width:8%;padding: 0 !important;border-width: 1px;">` + (data.warehouse ? data.warehouse : ``) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.size ? data.size : ``) + `</td>`;
				h += `<td style="text-align:center; width:6%;padding: 0 !important;border-width: 1px;">` + (data.weight ? data.weight : ``) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.retailPrice ? data.retailPrice : ``) + `</td>`;
				h += `<td style="text-align:center; width:4%;padding: 0 !important;border-width: 1px;">` + (data.originPrice ? data.originPrice : ``) + `</td>`;
				h += `<td style="text-align:center;	width:4%;padding: 0 !important;border-width: 1px;">` + (data.unitName ? data.unitName : ``) + `</td>`;
				h += `<td style="text-align:center; width:4%;padding: 0 !important;border-width: 1px;">` + (data.numPerBox ? data.numPerBox : ``) + `</td>`;
				h += `<td style="text-align:center; width:5%;padding: 0 !important;border-width: 1px;">` + (data.numBuyMin ? data.numBuyMin : ``) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.numBuyMinSecond ? data.numBuyMinSecond : ``) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.period) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.timeArrivePredict ? data.timeArrivePredict : ``) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.numAll) + `</td>`;
				h += `<td style="text-align:center; width:8%;padding: 0 !important;border-width: 1px;">` + (data.numPreBuy) + `</td>`;
			}

			//h += `<td style="text-align:center; width:8%;"><a class="layui-btn layui-btn-danger layui-btn-sm" data-index="` + i + `" lay-filter="remove"><i class="layui-icon layui-icon-delete"></i>移除</a></td>`
			return h;
		},


		loadGrid_3:function () { // 加载表格
			return `<table class="layui-table" lay-skin="row" style="margin:0;"><thead>`+this.loadGrid_3_OfThead()+`</thead><tbody>`+this.loadGrid_3_OfTbody()+`</tbody></table>`;
		},
		reloadGrid_3:function () { // 重新加载第三张表格
			$('#'+this.c.id_grid_3).html(this.loadGrid_3());
			this.listenGrid_3();
		},
		loadGrid_3_OfThead:function () { // 加载表头
			var h = `<thead><tr>`;
			h += `<th style="width:60px; text-align: center; color: #000000;padding: 0 !important;">
							<input type="checkbox" id="checkAll_3" lay-skin="primary" lay-filter="checkAll_3">
						</th>`;
			h += `<th style="width:30%; text-align: center;color: #000000;padding: 0 !important;">商品编码</th>`;
			h += `<th style="width:30%; text-align: center;color: #000000;padding: 0 !important;">运营公司编码</th>`;
			h += `<th style="width:30%; text-align: center;color: #000000;padding: 0 !important;">运营公司简称</th>`;
			return h;
		},
		loadGrid_3_OfTbody:function () { // 加载表tbody
			var t = this;
			var h = `<tbody id="tbody_3">`;
			for(var i=0;i<t.c.data3.length;i++){
				h += `<tr id="table_3_th_`+i+`">`;
				h += t.loadTableTdOfTbody_3(t.c.data3[i],i);
				h+= `</tr>`;
			}

			h += `</tbody>`;
			return h;
		},
		loadTableTdOfTbody_3:function (data,i) { // 加载表格行
			var h = ``;
			h += `<td style="text-align:center;padding:0;">
					<input type="checkbox" class="chBox_3"  lay-skin="primary" data-index="` + i + `"  lay-filter="checkBoxOne_3">
					</td>`;
			h += `<td style="text-align:center; width:30%;padding: 0 !important;border-width: 1px;" data-type="boutiqueCode">` + data.boutiqueCode + `</td>`;
			h += `<td style="text-align:center; width:30%;padding: 0 !important;border-width: 1px;">` + (data.vgsbm ? data.vgsbm : ``) + `</td>`;
			h += `<td style="text-align:center;	width:30%;padding: 0 !important;border-width: 1px;">` + (data.vgsjc ? data.vgsjc : ``) + `</td>`;
			return h;
		},


		listenAll:function () { // 添加监听
			var t = this;
			
			var domTable = $('#' + t.c.id_tab_1);

			// 监听标签页1
			t.listenTab_1();

			// 监听标签页2
			t.listenTab_2();

			// 监听标签页3
			t.listenTab_3();

			// 表单控件重新加载
			form.render();
		},
		listenTab_1:function () { // 添加监听1
			var t = this;

			var domTab = $('#' + t.c.id_tab_1);
			
			// 监听“新增”按钮
			domTab.find('a[lay-event="event-to-select"]').on('click',function (e) {
				layui.YsModal.init({modalKey: 'TB_Site', colCode: 'aaaa', parentObj: t, extraData: {useIn: 'addSite'}});
			});

			//全选
			layui.form.on('checkbox(checkAll)', function(data){
				var elem = data.elem;
				$(".chBox").prop("checked", elem.checked);
				var checkedIndex = [];
				$(".chBox").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				t.c.checkedIndex_1 = checkedIndex;
				//console.log('t.c.checkedIndex',t.c.checkedIndex_1);
				layui.form.render();
			});
			// 列表里的小选择框点击
			layui.form.on('checkbox(checkBoxOne)', function(data){
				var elem = data.elem;
				//console.log('elem',elem);
				if ($(".chBox").not('input:checked').length) {
					$('#checkAll').prop("checked", false);
				} else {
					$('#checkAll').prop("checked", true);
				}
				var checkedIndex = [];
				$(".chBox").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				t.c.checkedIndex_1 = checkedIndex;
				//console.log('t.c.checkedIndex',t.c.checkedIndex_1);
				layui.form.render();
			});


			// 监听“删除”按钮
			$('a[lay-event="event-to-del"]').on('click',function (e) {
				var checkedIndexList = t.c.checkedIndex_1;
				console.log('t.c.checkedIndex',t.c.checkedIndex_1);
				if (checkedIndexList.length ==0 || checkedIndexList==null){
					return layer.msg("请至少选择一条要删除的数据!");
				}
				if (checkedIndexList.length >= t.c.data.length){
					return layer.msg("删除失败,子件列表至少需要一条!");
				}
				var oldData = [];
				for (var i = 0; i < t.c.data.length; i++) {
					for (var j = 0; j < checkedIndexList.length; j++) {
						if(i == checkedIndexList[j]){
							oldData.push(t.c.data[i].id);
						}
					}
				}
				if(oldData.length>0){
					t.delYes(oldData,checkedIndexList);
				}

			}),
			
			t.listenGrid_1();
		},
		listenTab_2:function () { // 添加监听2
			var t = this;

			var domTab = $('#' + t.c.id_tab_2);
			
			// 监听“添加商品”按钮
			domTab.find('.btn-add-sys_col_all').on('click',function (e) {
				// 选择精品
				layui.YsModal.init({modalKey: 'TP_Boutique', colCode: '', parentObj: t, extraData: {useIn: 'addGoods'}})
				return;
			});
			
			// 监听“保存调货信息”按钮
			domTab.find('.btn-save-tp_boutique_setting').on('click',function (e) {
				var indexOfLoading = layer.load(1, {
					shade: [0.5,'#000000'] //0.1透明度的白色背景
				});
				$.ajax({
					type: "POST",
					url: '/api/inter/tpBoutique/editDetailBatch',
					data: {boutiqueId: t.c.boutiqueId, detailArr: JSON.stringify(t.c.data2)},
					success: function (res) {
						layer.msg(res.msg);
						setTimeout(function(){
							layer.close(indexOfLoading);
						}, 1000);
					}
				});
				return;
			});


			//全选
			layui.form.on('checkbox(checkAll_2)', function(data){
				var elem = data.elem;
				$(".chBox_2").prop("checked", elem.checked);
				var checkedIndex = [];
				$(".chBox_2").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				layui.form.render();
			});
			
			// 列表里的小选择框点击
			layui.form.on('checkbox(checkBoxOne_2)', function(data){
				var elem = data.elem;
				//console.log('elem',elem);
				if ($(".chBox_2").not('input:checked').length) {
					$('#checkAll_2').prop("checked", false);
				} else {
					$('#checkAll_2').prop("checked", true);
				}
				var checkedIndex = [];
				$(".chBox_2").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				layui.form.render();
			});
			t.listenGrid_2();
		},
		listenTab_3:function () { // 添加监听3
			var t = this;

			var domTab = $('#' + t.c.id_tab_3);

			// 监听“新增”按钮
			domTab.find('a[lay-event="event-to-select-3"]').on('click',function (e) {
				//layui.YsModal.init({modalKey: 'THR_OperateCompanyApply', colCode: 'aaaa', parentObj: t, extraData: {useIn: 'addAuth'}});
				//layui.YsModal.init({modalKey: 'THR_OperateCompanyApply', type: 'checkbox', uniqueKey: 'vgsbm', parentObj: t, selectedData: selectedDatas, sameCode: 'orgNamePointMonth'});
				layui.YsModal.init({
					modalKey: 'THR_OperateCompanyApply',
					type: 'checkbox',
					uniqueKey: 'vgsbm',
					parentObj: t,
					selectedData: []
				})
			});

			//全选
			layui.form.on('checkbox(checkAll_3)', function(data){
				var elem = data.elem;
				$(".chBox_3").prop("checked", elem.checked);
				var checkedIndex = [];
				$(".chBox_3").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				t.c.checkedIndex_3 = checkedIndex;
				layui.form.render();
			});
			// 列表里的小选择框点击
			layui.form.on('checkbox(checkBoxOne_3)', function(data){
				var elem = data.elem;
				//console.log('elem',elem);
				if ($(".chBox_3").not('input:checked').length) {
					$('#checkAll_3').prop("checked", false);
				} else {
					$('#checkAll_3').prop("checked", true);
				}
				var checkedIndex = [];
				$(".chBox_3").each(function(k, v){
					if ($(v).is(':checked')) {
						checkedIndex.push($(v).attr('data-index'));
					}
				});
				t.c.checkedIndex_3 = checkedIndex;
				//console.log('t.c.checkedIndex',t.c.checkedIndex_1);
				layui.form.render();
			});


			// 监听“删除”按钮
			$('a[lay-event="event-to-del-3"]').on('click',function (e) {
				var checkedIndexList = t.c.checkedIndex_3;
				console.log('t.c.checkedIndex',t.c.checkedIndex_3);
				if (checkedIndexList.length ==0 || checkedIndexList==null){
					return layer.msg("请至少选择一条要删除的数据!");
				}
				var oldData = [];
				for (var i = 0; i < t.c.data3.length; i++) {
					var isOld = false;
					for (var j = 0; j < checkedIndexList.length; j++) {
						if(i == checkedIndexList[j] && t.c.data3[i].id!=null){
							isOld = true;
						}
					}
					if(isOld){
						oldData.push(t.c.data3[i].id);
					}
				}

				if(oldData.length>0){
					//var idJsonStr = JSON.stringify(oldData);
					t.delYes_3(oldData,checkedIndexList);
				}else{
					var newData = [];
					for (var i = 0; i < t.c.data3.length; i++) {
						var isDel = false;
						for (var j = 0; j < checkedIndexList.length; j++) {
							if(i == checkedIndexList[j]){
								isDel = true;
							}
						}
						if(!isDel){
							newData.push(t.c.data3[i]);
						}
					}
					t.c.data3 = newData;
					layer.msg("操作成功", {icon: 1});
					//$('#' + t.c.id).empty();
					//return t.reload(t.c);
					t.reloadGrid_3();
				}

			}),

				t.listenGrid_3();
		},
		listenGrid_1:function () { // 添加表格监听1
			var t = this;

			var domGrid = $('#' + t.c.id_grid_1);
			
			// 监听表格中的按钮
			domGrid.find('button[lay-filter="editSingle"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				t.toEdit(t.c.data[indexOfRow].id,t.c.data[indexOfRow].countryName);
				return;
			});
			domGrid.find('button[lay-filter="detailSingle"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				t.toDetail(t.c.data[indexOfRow].id,t.c.data[indexOfRow].countryName);
				return;
			});

			domGrid.find('button[lay-filter="removeSingle"]').on('click',function (e) {
				var indexOfRow = $(this).attr('data-index');
				t.toDel(t.c.data[indexOfRow].id);
				return;
			});
			// 表单控件重新加载
			form.render();
		},
		listenGrid_2:function () { // 添加表格监听2
			var t = this;

			var domGrid = $('#' + t.c.id_grid_2);
            
			// 监听各个输入框
			domGrid.find('input[lay-filter="_input"]').on('change',function (e) {
				var index = $(this).attr('data-index');
				var key = $(this).attr('data-type');
				var value = $(this).val();
				t.c.data2[index][key] = value;
				return;
			});
            
			// 监听选择仓库
			domGrid.find('input[lay-filter="_select_warehose"]').on('click',function (e) {
				var rowIndex = $(this).attr('data-index');
				var key = $(this).attr('data-type');
				layui.YsModal.init({modalKey: 'TS_DepotInfo_For_TpBoutique', colCode: '', parentObj: t, extraData: {useIn: 'changeWarehouse', rowIndex: rowIndex}});
				return;
			});
			
			// 监听预计到货时间
			domGrid.find('input[lay-filter="_select_timeArrivePredict"]').each(function(){
				var index = $(this).attr('data-index');
				layui.laydate.render({
					elem: this,
					type: 'date',
					calendar: true,
					btns: ['clear', 'confirm', 'now'],
					done: function (value, date) {
						//这里时选中后触发事件
						//value是选中的值
						var time = value;
						t.c.data2[index]['timeArrivePredict'] = value;
						console.log(t.c.data2);
					}
				});
			});
            
			// 监听箱规选择
			domGrid.find('i[lay-filter="_select_gaugemaintenance"]').on('click',function (e) {
				var rowIndex = $(this).attr('data-index');
				console.log('t.c.data',t.c.data);
		    	var code = t.c.data2[rowIndex]['code'];
		    	if(code == null || code == undefined || code == '') {
		    		layer.msg('请先输入商品编码');
		    		return;
		    	}
		    	
		    	var warehouse = t.c.data2[rowIndex]['warehouse'];
		    	if(warehouse == null || warehouse == undefined || warehouse == '') {
		    		layer.msg('请先填写仓库');
		    		return;
		    	}
		    	
            	layui.YsModal.init({modalKey: 'TP_GaugeMaintenance', colCode: '', parentObj: t, extraData: {useIn: 'changeGauge', rowIndex: rowIndex}, conditionsDefault: [{code: 'warehouseAddress', value: warehouse}]});
				return;
			});

			// 监听“移除”
			$('a[lay-event="event-to-delete-single-2"]').on('click',function (e) {
				var dataIndex = $(this).attr('data-index');
				layer.confirm('确定删除？ ', {
						btn: ['确定','取消'] //按钮
					}, function(index){
						var id = t.c.data2[dataIndex]['id'];
						if(id != null && id != undefined && id != '') {
							$.ajax({
								type: "POST",
								url: '/api/inter/tpBoutique/deleteDetail',
								data: {id: id},
								success: function (res) {
									layer.msg(res.msg);
									if (res.code == 0) {
										t.c.data2.splice(dataIndex, 1);
										t.reloadGrid_2();
									}
								}
							});
						} else {
							t.c.data2.splice(dataIndex, 1);
							t.reloadGrid_2();
							//$('#' + t.c.id_grid_2).html(t.loadGrid_2());
							//layui.form.render();
						}
						layer.close(index);
					}, function(index){
						layer.close(index);
					}
				);
			});
            
			// 表单控件重新加载
			form.render();
		},
		listenGrid_3:function () { // 添加表格监听3
			var t = this;

			var domGrid = $('#' + t.c.id_grid_3);

			// 表单控件重新加载
			form.render();
		},
		toEdit:function(siteId,countryName) {
			var t = this;
			var code = t.c.code;
			var w=($(window).width());
			var h=($(window).height());
			layer.open({
				title:"精品库站点详情信息-编辑("+code+"-"+countryName+"-"+siteId+")",
				type: 2,
				area: [w+'px', h +'px'],
				fix: true,
				maxmin: false,
				shadeClose: true,
				shade:0.4,
				content:"/web/business/tpBoutiqueSiteDetail/toEdit?id="+siteId});

			return;
			//t.openUrl("精品库站点详情信息-编辑("+code+"-"+countryName+"-"+siteId+")","/web/business/tpBoutiqueSiteDetail/toEdit?id="+siteId,1);
		},
		isFrom1_0: function() {
			if(window.top.isMobile!=undefined || window.top.isMobile!=null) {
				return false;
			} else {
				return true;
			}
		},
		openUrl: function(title, url, toType) { // toType，打开页面方式，1标签页2新页面
			var isOn1_0 = this.isFrom1_0();
			if (isOn1_0 == true) {
				window.open(url);
			} else {
				if (toType != null && toType != undefined) {
					if (toType == 1) {
						window.top.add_tab(title,url);
					} else {
						window.open(url);
					}
				}
			}
		},
		toDetail:function(siteId,countryName) {
			var t = this;
			var code = t.c.code;
			var w=($(window).width());
			var h=($(window).height());
			layer.open({
				title:"精品库站点详情信息-详情("+code+"-"+countryName+"-"+siteId+")",
				type: 2,
				area: [w+'px', h +'px'],
				fix: true,
				maxmin: false,
				shadeClose: true,
				shade:0.4,
				content:"/web/business/tpBoutiqueSiteDetail/toDetail?id="+siteId});

			return;
			//t.openUrl("精品库站点详情信息-详情("+code+"-"+countryName+"-"+siteId+")","/web/business/tpBoutiqueSiteDetail/toDetail?id="+siteId,1);
		},

		//确定删除
		delYes:function(spId,checkedIndexList){
			var siteId = JSON.stringify(spId);
			var t = this;
			var c = this.c;
			var loadIndex = layer.load(2);
			$.ajax({
				url: '/api/inter/tpBoutiqueSiteDetail/del',
				data: {
					'ids':siteId,
					'boutiqueId': t.c.boutiqueId
				},
				type: 'POST',
				async: true,
				success: function (result) {
					if(result.code==0){
						layer.close(loadIndex);
						layer.msg("操作成功", {icon: 1});
						//表格重载
						//layui.table.reload('detail_table', { });
						var newData = [];
						for (var i = 0; i < c.data.length; i++) {
							var isDel = false;
							for (var j = 0; j < spId.length; j++) {
								if(c.data[i].id==spId[j]){
									isDel = true;
								}
							}
							if(!isDel){
								newData.push(c.data[i]);
							}
						}
						c.data = newData;
						$('#' + c.id).empty();
						return t.reload(c);


					}else {//失败
						layer.close(loadIndex);
						layer.msg(result.msg, {icon: 2});
					}
				},
				error: function () {
					layer.close(loadIndex);
					layer.msg("删除失败，请稍后再试！", {icon: 2});
				}
			});
		},


		//确定删除
		delYes_3:function(spId,checkedIndexList){
			var ids = JSON.stringify(spId);
			var t = this;
			var c = this.c;
			var loadIndex = layer.load(2);
			$.ajax({
				url: '/api/inter/tpBoutique/delByAuth',
				data: {
					'ids':ids
				},
				type: 'POST',
				async: true,
				success: function (result) {
					if(result.code==0){
						layer.close(loadIndex);
						layer.msg("操作成功", {icon: 1});
						//表格重载
						//layui.table.reload('detail_table', { });
						var newData = [];
						for (var i = 0; i < c.data3.length; i++) {
							var isDel = false;
							for (var j = 0; j < spId.length; j++) {
								if(c.data3[i].id==spId[j]){
									isDel = true;
								}
							}
							if(!isDel){
								newData.push(c.data3[i]);
							}
						}
						c.data3 = newData;
						//$('#' + c.id).empty();
						//return t.reload(c);
						t.reloadGrid_3();

					}else {//失败
						layer.close(loadIndex);
						layer.msg(result.msg, {icon: 2});
					}
				},
				error: function () {
					layer.close(loadIndex);
					layer.msg("删除失败，请稍后再试！", {icon: 2});
				}
			});
		},

		removeRow:function(index) { // 重新加载表格
			var t = this;
			t.c.data.splice(index, 1);
			return t.reload(t.c);
		},
		getData:function () {
			return this.c.data3;
		},
		init:function (c) {this.f(c);this.load();return object;},
		reload:function (c) {c.data = this.c.data;$('#' + this.c.id).empty();return this.init(c);},
		addRow:function (row) {
			var c = this.c;
			var t = this;
			c.data.push(row);
			var h =  `<tr id="table_th_`+(c.data.length-1)+`">`;
			h += t.loadTableTdOfTbody(row,c.data.length-1);
			h+= `</tr>`;
			$('#tbody').append(h);
			t.listenGrid_1();
		},
        addRow2:function (row) {
			var c = this.c;
			var t = this;
			c.data2.push(row);
			var h = `<tr id="table_2_th_`+(c.data2.length-1)+`">`
			+ t.loadTableTdOfTbody_2(row,c.data2.length-1)
			+ `</tr>`;
			$('#tbody_2').append(h);
			t.listenGrid_2();
        },
		addRow3:function (row) {
			var c = this.c;
			var t = this;
			c.data3.push(row);
			var h = `<tr id="table_3_th_`+(c.data3.length-1)+`">`
				+ t.loadTableTdOfTbody_3(row,c.data3.length-1)
				+ `</tr>`;
			$('#tbody_3').append(h);
			t.listenGrid_3();
		},
		addRows:function (rows) {
			var c = this.c;
			for (var i = 0; i < rows.length; i++) {
				c.data.push(rows[i]);
			}
			$('#' + c.id).empty();
			return this.reload(c);
		},
		addRows3:function (rows) {
			var c = this.c;
			var t = this;
			for (var i = 0; i < rows.length; i++) {
				var row = rows[i];
				c.data3.push(row);
				var h = `<tr id="table_3_th_`+(c.data3.length-1)+`">`
					+ t.loadTableTdOfTbody_3(row,c.data3.length-1)
					+ `</tr>`;
				$('#tbody_3').append(h);
			}
			t.listenGrid_3();
		},
		editRow:function (index, row) {
			var c = this.c;
			c.data[index] = row;
			$('#' + c.id).empty();
			return this.reload(c);
		},
		editRowOfAttr:function (index, row) {
			var c = this.c;
			for(var key in row){
				c.data[index][key] = row[key]
			}
			$('#' + c.id).empty();
			return this.reload(c);
		},
		reloadRows:function (rows) {
			var c = this.c;
			c.data = rows;
			return this.reload(c);
		},
		//返回
		matchValuesAfterModalSelectRadio:function(colCode, data, extraData) {
			console.log('选择的',data);
			var t = this;
			
			// 添加站点详情
			if(extraData.useIn == 'addSite') {
				$.ajax({
					url: '/api/inter/tpBoutiqueSiteDetail/toAddOnlySite',
					data: {
						'siteId':data.id,
						'boutiqueId': t.c.boutiqueId
					},
					type: 'POST',
					async: false,
					success: function (result) {
						console.log('result:',result);
						if (result.code == 0) {
							t.addRow(result.data.tpBoutiqueSiteDetail);
						}else {//失败
							layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
						}
					},
					error: function () {
						layer.msg('不好意思，系统出现问题了，请稍后重试！', {icon: 2});
					}
				});
        	}

        	// 添加商品
			else if(extraData.useIn == 'addGoods') {
                var row = {};
                row['code'] = data.code;
                row['period'] = 0;
                row['numAll'] = 0;
                row['numPreBuy'] = 0;
                t.addRow2(row);
        	}
        	// 选择箱规
        	else if(extraData.useIn == 'changeGauge') {
        		var rowIndex = extraData.rowIndex;
	            t.c.data2[rowIndex]['size'] = data.length + '*' + data.width + '*' + data.height;
	            t.c.data2[rowIndex]['weight'] = data.weight;
	            t.c.data2[rowIndex]['numPerBox'] = data.num;
				t.reloadGrid_2();
        	}
        	// 选择仓库
        	else if(extraData.useIn == 'changeWarehouse') {
        		var rowIndex = extraData.rowIndex;
	            t.c.data2[rowIndex]['warehouse'] = data.depotName;
				t.reloadGrid_2();
        	}
			// 添加商品
			else if(extraData.useIn == 'addAuth') {
				var row = {};
				row['boutiqueCode'] = t.c.code;
				row['vgsbm'] = data.vgsbm;
				row['vgsjc'] = data.vgsjc;
				t.addRow3(row);
			}
		},
		//多选框
		matchValuesAfterModalSelectCheckbox: function (obj1, obj2, obj3) {
			var t = this;
			var rowCurrents = [];
			for (var i = 0; i < obj1.length; i++) {
				var obj = obj1[i];
				var isAdd = false;
				for(var j = 0; j < t.c.data3.length; j++){
					if(t.c.data3[j].vgsbm == obj.vgsbm){
						isAdd = true;
					}
				}
				if(!isAdd){
					var rowCurrent = obj;
					rowCurrent.id = null;
					rowCurrent.boutiqueCode = t.c.code;
					rowCurrent.vgsbm = obj.vgsbm;
					rowCurrent.vgsjc = obj.vgsjc;
					rowCurrents.push(rowCurrent);
				}

			}
			t.addRows3(rowCurrents);
		}
	};
	exports('simple_table_TP_BoutiqueSiteDetail', object);
});